/*
 * @Author: CC-TSR
 * @Date: 2021-01-08 08:57:20
 * @LastEditTime: 2021-12-19 01:32:25
 * @FilePath: \人员轨迹\src\main.js
 * @可以输入预定的版权声明、个性签名、空行等
 */
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "./plugins/jquery";
import "./plugins/axios";
import "./plugins/cookies.js";
import "./plugins/iview";

import echarts from 'echarts'

// import _ from "lodash"
import FeatureLayer from "@arcgis/core/layers/FeatureLayer";
import animated from 'animate.css'
import '@arcgis/core/assets/esri/themes/light/main.css';


import esriConfig from "@arcgis/core/config.js";
esriConfig.assetsPath = "./assets";

Vue.use(animated)
Vue.prototype.$echarts = echarts;
Vue.config.productionTip = false;
let peopleLayer = new FeatureLayer({
  url: "http://59.218.251.20:31993/arcgis/rest/services/userstation/FeatureServer/0",
})
let trailsRenderer = {
  type: "simple",
  symbol: {
    type: "simple-line",
    style: "long-dash",
    color: "#ff0000",
    width: "2px"
  }
};
let trailLayer = new FeatureLayer({
  url: "http://59.218.251.20:31993/arcgis/rest/services/userstation/FeatureServer/2",
  renderer: trailsRenderer,
  outFields: ["*"],
  popupTemplate: trailLayerTemplate()
})

function trailLayerTemplate() {
  return {
    title: "轨迹信息" + "{objectid}",
    content: [{
      type: "fields",
      fieldInfos: [{
        fieldName: "id",
        label: "轨迹编号",
        format: {
          places: 0,
          digitSeparator: true
        }
      }, {
        fieldName: "name",
        label: "轨迹名称",
        format: {
          places: 0,
          digitSeparator: true
        }
      }, {
        fieldName: "remark1",
        label: "采集时间",
        format: {
          places: 0,
          digitSeparator: true
        }
      }, {
        fieldName: "remark2",
        label: "备注信息",
        format: {
          places: 0,
          digitSeparator: true
        }
      }]
    }]
  };
}
let trailsPointRenderer = {
  type: "simple",
  symbol: {
    type: "simple-marker",
    style: "circle",
    color: "yellow",
    size: "10px",
    outline: {
      color: "red",
      width: 1
    }
  }
}
let trailPointLayer = new FeatureLayer({
  url: "http://59.218.251.20:31993/arcgis/rest/services/userstation/FeatureServer/1",
  renderer: trailsPointRenderer,
  outFields: ["*"],
  popupTemplate: trailsPointTemplate()
})

function trailsPointTemplate() {
  return {
    title: "轨迹点信息" + "{objectid}",
    content: [{
      type: "fields",
      fieldInfos: [{
        fieldName: "phone",
        label: "手机标识",
        format: {
          places: 0,
          digitSeparator: true
        }
      }, {
        fieldName: "stay",
        label: "停留时长",
        format: {
          places: 0,
          digitSeparator: true
        }
      }, {
        fieldName: "time",
        label: "采集时间",
        format: {
          places: 0,
          digitSeparator: true
        }
      }, {
        fieldName: "location",
        label: "采集地点",
        format: {
          places: 0,
          digitSeparator: true
        }
      }]
    }]
  };
}
let trailsPointHotRenderer = {
  type: "heatmap",
  colorStops: [{
      color: "rgba(63, 40, 102, 0)",
      ratio: 0
    },
    {
      color: "#472b77",
      ratio: 0.083
    },
    {
      color: "#4e2d87",
      ratio: 0.166
    },
    {
      color: "#563098",
      ratio: 0.249
    },
    {
      color: "#5d32a8",
      ratio: 0.332
    },
    {
      color: "#6735be",
      ratio: 0.415
    },
    {
      color: "#7139d4",
      ratio: 0.498
    },
    {
      color: "#7b3ce9",
      ratio: 0.581
    },
    {
      color: "#853fff",
      ratio: 0.664
    },
    {
      color: "#a46fbf",
      ratio: 0.747
    },
    {
      color: "#c29f80",
      ratio: 0.83
    },
    {
      color: "#e0cf40",
      ratio: 0.913
    },
    {
      color: "#ffff00",
      ratio: 1
    }
  ],
  maxPixelIntensity: 25,
  minPixelIntensity: 0
}
let trailPointHotLayer = new FeatureLayer({
  url: "http://59.218.251.20:31993/arcgis/rest/services/userstation/FeatureServer/1",
  renderer: trailsPointHotRenderer,
  visible: false
})
let stationpoint = new FeatureLayer({
  url: "http://59.218.251.20:31993/arcgis/rest/services/userstation/FeatureServer/4",
})
let userpoint = new FeatureLayer({
  url: "http://59.218.251.20:31993/arcgis/rest/services/userstation/FeatureServer/6",
})

Vue.prototype.$commonLayers = {
  // 人基础属性信息图层
  peopleLayer: peopleLayer,
  trailLayer: trailLayer,
  trailPointLayer: trailPointLayer,
  trailPointHotLayer: trailPointHotLayer,
  stationpoint: stationpoint,
  userpoint: userpoint

}
// Vue.prototype._ = _

Vue.axios.interceptors.response.use(
  res => {
    if (res.data.code == 401) {
      sessionStorage.removeItem("token");
      sessionStorage.removeItem("selfInfo");
      sessionStorage.removeItem("name");
      location.reload("/login");
    }
    return res;
  },
  error => {
    if (error.response.status == 401) {
      sessionStorage.removeItem("token");
      sessionStorage.removeItem("selfInfo");
      sessionStorage.removeItem("name");
      location.reload("/login");
    }
  }
);
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");